import { NextResponse } from "next/server"
import type { Comment } from "@/types/comment"

// 模拟数据
const mockComments: Comment[] = [
  {
    id: 1,
    user: {
      id: "1",
      name: "小琴",
      avatar: "/placeholder.svg?height=40&width=40",
    },
    content: "这张都是每首歌都很棒！特别喜欢第一首，旋律太美了",
    timestamp: "2024年1月10日 19:38",
    likes: 42,
    isLiked: false,
    replies: [
      {
        id: 2,
        user: {
          id: "2",
          name: "音乐爱好者",
          avatar: "/placeholder.svg?height=40&width=40",
        },
        content: "同感！每一首都很用心",
        timestamp: "2024年1月10日 20:15",
        likes: 8,
        isLiked: false,
      },
    ],
  },
]

export async function GET(request: Request) {
  const { searchParams } = new URL(request.url)
  const contentId = searchParams.get("contentId")
  const contentType = searchParams.get("contentType")

  // 这里可以根据 contentId 和 contentType 从数据库获取评论
  // 现在我们返回模拟数据
  return NextResponse.json({
    code: 200,
    data: mockComments,
  })
}

export async function POST(request: Request) {
  const body = await request.json()
  const { contentId, contentType, content, userId } = body

  // 验证必要参数
  if (!contentId || !contentType || !content) {
    return NextResponse.json(
      {
        code: 400,
        message: "Missing required parameters",
      },
      { status: 400 },
    )
  }

  // 创建新评论
  const newComment: Comment = {
    id: Date.now(),
    user: {
      id: userId || "current-user", // 实际应用中应该从session获取
      name: "当前用户",
      avatar: "/placeholder.svg?height=40&width=40",
    },
    content,
    timestamp: new Date().toLocaleString("zh-CN", {
      year: "numeric",
      month: "numeric",
      day: "numeric",
      hour: "numeric",
      minute: "numeric",
    }),
    likes: 0,
    isLiked: false,
  }

  return NextResponse.json({
    code: 200,
    data: newComment,
  })
}

